package main

import (
	"log"
	"qimo_lpz/config"
	"qimo_lpz/models"
	"qimo_lpz/routes"
)

func main() {
	// 加载配置
	cfg := config.LoadConfig()

	// 初始化数据库
	err := models.InitDB(cfg)
	if err != nil {
		log.Fatalf("Failed to initialize database: %v", err)
	}

	// 自动迁移
	err = models.AutoMigrate()
	if err != nil {
		log.Fatalf("Failed to auto migrate: %v", err)
	}

	// 设置路由
	r := routes.SetupRouter()

	// 启动服务器
	log.Printf("Server is running on port %s", cfg.AppPort)
	if err := r.Run(":" + cfg.AppPort); err != nil {
		log.Fatalf("Failed to start server: %v", err)
	}
}